/* 
  1，选择参数
  2，环境，
  3，地区
*/
var child_process = require("child_process");
let param_verison = "2025-01-11";
let package_name = "safe-rs-company";
let ip = "10.10.112.61";
let pasw = "bnh1923";
let city = "fu-yang";
let env = "prod";

const child = child_process.exec(`cd /Volumes/ALL/wrok/safe/safe-rs-company; npm run build:test:${city};
  cd dist/;
  tar -zcvf ../../dist/${package_name}-${param_verison}.tgz --exclude=.git --exclude=logs --exclude=node_modules .
  `);

// 监听命令输出
child.stdout.on("data", (data) => {
  console.log(data.toString());
});

child.stderr.on("data", (data) => {
  console.log(data.toString());
});

child.on("close", (code) => {
  console.log(`命令退出，退出码 ${code}`);

  if (code == 0) {
    let sh = `
    sshpass -p ${pasw} scp -o StrictHostKeyChecking=no /Volumes/ALL/wrok/safe/dist/${package_name}-${param_verison}.tgz admin@${ip}:~/${package_name};
    sshpass -p ${pasw} ssh admin@${ip} "cd ${package_name}; tar -zxvf ${package_name}-${param_verison}.tgz;"
    `;
    child_process.exec(sh, function (error, stdout, stderr) {
      console.log("error:" + error);
      console.log("stdout:" + stdout);
      console.log("stderr:" + stderr);
    });
  }
});
